Skip to content

Norm Samples updates for B,S,H style tensor inputs#432

Open
rmhaskarnvidia wants to merge 5 commits into
NVIDIA:developfrom
rmhaskarnvidia:rmhaskar/norm_benchmark_sample_updates
Open

Norm Samples updates for B,S,H style tensor inputs#432
rmhaskarnvidia wants to merge 5 commits into
NVIDIA:developfrom
rmhaskarnvidia:rmhaskar/norm_benchmark_sample_updates

Conversation

@rmhaskarnvidia

@rmhaskarnvidia rmhaskarnvidia commented Jul 23, 2026

Copy link
Copy Markdown

Before submitting

  • I agree to license this contribution under the terms of LICENSE.txt.
  • I ran pre-commit run and committed any formatting changes.

Affected area

Documentation or samples

Summary

Layout and RMS Norm samples are updated to accept direct B,S,H tensor shapes

Why

cudnn Backend supports passing X tensor as (B,S,H) for LN/RMS norm. All FE samples transformed the input to (B*S, H ,1,1) which is not really necessary

API and compatibility impact

None

Testing

./bin/samples "LayerNorm Backward"
Filters: "LayerNorm Backward"
Randomness seeded to: 1937091254
All tests passed (7 assertions in 1 test case)

./bin/samples "LayerNorm Inference"
Filters: "LayerNorm Inference"
Randomness seeded to: 3002993422
All tests passed (9 assertions in 1 test case)

./bin/samples "LayerNorm Training"
Filters: "LayerNorm Training"
Randomness seeded to: 4011977597
All tests passed (7 assertions in 1 test case)

/bin/samples "RmsNorm Backward"
Filters: "RmsNorm Backward"
Randomness seeded to: 572308681
All tests passed (8 assertions in 1 test case)

./bin/samples "RmsNorm Inference"
Filters: "RmsNorm Inference"
Randomness seeded to: 4203307452
All tests passed (8 assertions in 1 test case)

Summary by CodeRabbit

  • Improvements
    • LayerNorm and RMSNorm now more consistently infer backward tensor shapes/strides, aligning DY/DX with X and scale-related tensors with SCALE when not explicitly set.
  • Examples & Tests
    • Updated LayerNorm and RMSNorm C++ samples and Python notebooks to use explicit 3D (batch, sequence, hidden) layouts (including corresponding scale/bias and updated mean/inv-variance handling).
    • Updated Python and test-suite tensor reshaping and normalization references to match the new layouts.
    • Corrected a C++ test skip message for SGBN Add Relu.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 78cc8f9f-a65e-49df-9125-40c6cc254ce0

📥 Commits

Reviewing files that changed from the base of the PR and between 77f4157 and 2202f28.

📒 Files selected for processing (4)
  • samples/python/20_layernorm_forward.ipynb
  • samples/python/21_layernorm_backward.ipynb
  • samples/python/29_rmsnorm.ipynb
  • test/python/test_layernorm.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/python/test_layernorm.py
  • samples/python/20_layernorm_forward.ipynb
  • samples/python/21_layernorm_backward.ipynb
  • samples/python/29_rmsnorm.ipynb

📝 Walkthrough

Walkthrough

LayerNorm and RMSNorm tensor layouts changed from flattened 4D forms to explicit sequence-oriented shapes. Backward property inference now copies dimensions and strides from input and scale tensors, with corresponding C++ samples, Python notebooks, and tests updated.

Changes

Normalization layout updates

Layer / File(s) Summary
Backward property inference
include/cudnn_frontend/node/dln.h, include/cudnn_frontend/node/rmsnorm.h
Backward tensors inherit dimensions and strides directly from input and scale tensors.
C++ normalization samples
samples/cpp/norm/*.cpp
LayerNorm and RMSNorm samples use 3D tensor layouts, updated intermediates, device surfaces, and corrected skip messages.
LayerNorm forward validation
samples/python/20_layernorm_forward.ipynb, samples/python/22_layernorm_inference.ipynb, test/python/test_layernorm.py
Forward and inference examples use B-S-H inputs, broadcast parameters, and last-dimension reference calculations.
LayerNorm backward validation
samples/python/21_layernorm_backward.ipynb
Wrapper and Python binding backward flows use revised shapes and gradient comparisons.
RMSNorm validation
samples/python/29_rmsnorm.ipynb, test/python/test_rmsnorm.py
RMSNorm examples and tests use 3D sequence tensors and normalize over the last dimension.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested labels: cat-feature

Suggested reviewers: anerudhan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: switching norm samples to direct B,S,H tensor inputs.
Description check ✅ Passed The description follows the template well and includes the required sections for area, summary, why, compatibility, and testing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
samples/python/29_rmsnorm.ipynb (1)

318-318: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Run black-jupyter on the modified notebook.

The trailing semicolons are not Black-formatted. As per coding guidelines, Python tutorial notebooks must use black-jupyter formatting.

Also applies to: 436-436

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@samples/python/29_rmsnorm.ipynb` at line 318, Run black-jupyter on the
modified notebook, including the cells containing inv_var.set_name(...) and the
corresponding code at the other referenced location, so Black removes the
trailing semicolons and applies standard formatting throughout the notebook.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@samples/python/29_rmsnorm.ipynb`:
- Line 18: Update the Open in Colab badge URL in the notebook’s introductory
markdown cell to reference 29_rmsnorm.ipynb instead of 28_rmsnorm.ipynb, leaving
the badge text and repository path unchanged.
- Around line 338-345: Update the Python Binding API setup before the
variant_pack definition to allocate local out_gpu and inv_var_gpu tensors,
rather than relying on variables created by the earlier wrapper flow. Ensure the
existing out and inv_var bindings continue to reference these locally defined
outputs when running the flow independently.

In `@test/python/test_layernorm.py`:
- Line 58: Update every reference torch.var call used by the LayerNorm
expected-value calculations to pass correction=0: test/python/test_layernorm.py
lines 58-58, samples/python/20_layernorm_forward.ipynb lines 168-170 and
258-260, and samples/python/21_layernorm_backward.ipynb lines 174-176 and
337-339. Preserve the existing dimensions and keepdim arguments.

---

Nitpick comments:
In `@samples/python/29_rmsnorm.ipynb`:
- Line 318: Run black-jupyter on the modified notebook, including the cells
containing inv_var.set_name(...) and the corresponding code at the other
referenced location, so Black removes the trailing semicolons and applies
standard formatting throughout the notebook.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3b1aa3cf-7be5-4702-9738-7390a6624071

📥 Commits

Reviewing files that changed from the base of the PR and between 3a9ed3f and 77f4157.

📒 Files selected for processing (11)
  • include/cudnn_frontend/node/dln.h
  • include/cudnn_frontend/node/rmsnorm.h
  • samples/cpp/norm/batchnorm.cpp
  • samples/cpp/norm/layernorm.cpp
  • samples/cpp/norm/rmsnorm.cpp
  • samples/python/20_layernorm_forward.ipynb
  • samples/python/21_layernorm_backward.ipynb
  • samples/python/22_layernorm_inference.ipynb
  • samples/python/29_rmsnorm.ipynb
  • test/python/test_layernorm.py
  • test/python/test_rmsnorm.py

Comment thread samples/python/29_rmsnorm.ipynb Outdated
Comment thread samples/python/29_rmsnorm.ipynb
Comment thread test/python/test_layernorm.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant